home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / asm_0_m.arj / L4.ASM < prev    next >
Assembly Source File  |  1987-05-13  |  22KB  |  1,008 lines

  1.     Page    80,132
  2.     Title    LIST --- Display contents of ASCII file
  3.  
  4.     Comment    |
  5.  
  6. Command    LIST
  7. ----------------
  8.  
  9.  Purpose:  To display the contents of an ASCII file, line by
  10.        line, with operator positioning commands.
  11.  
  12.  Format:   LIST    [d:][path]filename[.ext]
  13.  
  14.  Remarks:  An ASCII file of any    size may be listed.
  15.  
  16.     On the COMMAND line, enter a letter or control key:-
  17.  
  18.     Letter(s)    Control key    Function
  19.     -----------    ------------    ------------------------
  20.             Enter        continue to next page
  21.     Q, X        ESCape        terminate and exit to DOS
  22.     T        HOME        restart    from first block (top)
  23.     B        END        skip to    end of file (bottom)
  24.     D         PgDn        scroll down one    page
  25.     U        PgUp        scroll up one page
  26.     H or ?        F1        list commands (HELP)
  27.     L        left arrow    scroll left 20 columns
  28.     R        right arrow    scroll right 20    columns
  29.     P        up arrow    up one (previous) line
  30.     N        down arrow    down one (next)    line
  31.  
  32.     /text                find 'text'
  33.     A        F3        find next occurance of 'text'
  34.  
  35.             ctl-HOME    restart from CURRENT block
  36.             ctl-PgUp    restart from first block (TOP)
  37.             ctl-PgDn    skip to end of file (BOTTOM)
  38.             ctl-left-arrow    reset scroll to column 1
  39.  
  40.             F1        Help
  41.             F3        Find next
  42.             F10        Exit
  43.  
  44.  Restrictions:
  45.     All positioning    is relative to the current block in
  46.     storage. The size of the block depends on the amount of
  47.     memory available, up to    64K.
  48.  
  49.     The maximum record length currently allowed is 255.
  50.  
  51.     Logical    records    (ending    in LF and/or CR) are placed
  52.     into the DOS screen buffer - mono or color display.
  53.  
  54.     PC-DOS Version 2.0 or later is required.
  55.  
  56.     ANSI.SYS is NOT required.
  57.  
  58.  Scanning for text:
  59.     To scan for a character string, type a slash (/)
  60.     followed by one or more (up to 32) characters. The
  61.     scan text, but not the slash, is displayed on the
  62.     command line. The entire file, from the current line,
  63.     is scanned.
  64.  
  65.     If the text is found, the line containing it is displayed
  66.     as a blinking line.
  67.  
  68.     If the text is NOT found, an error message is displayed
  69.     and the display remains unchanged.
  70.  
  71.  Screen attributes:
  72.     There are three classes of attributes used. One for
  73.     normal display lines - lines 2 to 24, another for
  74.     special lines - lines 1 and 25, and a third for the
  75.     background color.
  76.  
  77.     These attributes may be changed by using DEBUG:
  78.  
  79.      at offset 11C = 09    ;special lines, hi-lighted or lt.blue
  80.      at offset 11D = 02    ;normal lines, green
  81.      at offset 11E = 00    ;background, black
  82.  
  83.     If these values don't match, you have a different version.
  84.     ----------------------------------------------------------
  85.  
  86.     Written    by Vernon Buerg for the IBM PC using DOS 2.0,
  87.     and is supplied for public domain use. Not for sale or hire.
  88.  
  89.     Version    1.5, June 2, 1984.                |
  90.  
  91.     Page
  92.  
  93. Bios    Segment    At 40h            ;DOS data area
  94.     Db    16 Dup (?)
  95. Flag    Dw    ?            ;Hardware features
  96.     Db    56 Dup (?)
  97. Cols    Dw    ?            ;Columns on screen
  98.     Db    23 Dup (?)
  99. A6845    Dw    ?            ;Base addr for active card
  100. Bios    Ends
  101.  
  102.  
  103. Cseg    Segment    Para Public 'CODE'
  104.     Assume    CS:Cseg,DS:Cseg,ES:Nothing
  105.     Org    100h
  106. List    Proc    Far
  107.     Mov    DX,Offset Stackx    ;Local stack
  108.     Mov    SP,DX
  109.     Push    DS            ;Standard linkage
  110.     Xor    AX,AX            ; for DOS return
  111.     Push    AX
  112.     Mov    AH,30h            ;Check for
  113.     Int    21h            ; DOS 2.0 or later
  114.     Cmp    AL,2
  115.     Jb    TooBad
  116.     Jmp    Start
  117.  
  118. TooBad:    Mov    DX,Offset Sorry        ;Say Version 2 required
  119.     Mov    AH,9
  120.     Int    21h
  121.     Ret
  122.     Page
  123. ;    Constants and work areas
  124.  
  125. Special    Db    09h            ;Attribute for attention
  126. Normal    Db    02h            ;Normal    display    attribute
  127. Foregrd    Db    07h            ;Fill attribute
  128. Blink    Equ    0Fh            ;Hilite    for FIND (143h blinks)
  129.  
  130. CR    Equ    0Dh
  131. LF    Equ    0Ah
  132. EOF    Equ    1Ah
  133. Eor    Equ    1            ;End-of-record
  134. Nodata    Equ    2            ;null record
  135.  
  136. Crt_Col    Dw    0            ;Columns for display monitor
  137. Crt_Buf    Dw    0            ;Addr of display buffer
  138. Crt_Prt    Dw    0            ;Addr of display port
  139.  
  140. Index    Dw    0            ;Current record    address
  141. Reclen    Dw    0            ; length
  142. Row    Db    2            ; display row
  143. Col    Db    1            ; display column
  144. Attr    Db    02h            ; screen attribute
  145. Blknum    Db    0            ; block    number
  146. Scroll    Dw    0            ;Scroll    left/right amount
  147. First    Dw    0            ;Ptr to    top line on screen
  148. Current    Dw    0            ;Ptr to    top after UP one
  149. Last    Dw    0            ;Ptr to    last record
  150.  
  151. Recaddr    Dw    0            ;addr of i/o buffer
  152. Handle    Dw    0            ;File handle from open
  153. Psize    Dw    16            ;Size of a paragraph
  154. Blksize    Dw    0            ;File read size
  155.  
  156. Switch1    Db    0
  157. Switch2    Db    0
  158. Numlf    Db    1            ;line feed count
  159. Numcr    Db    0            ;C/R count
  160.  
  161. TextMax    Db    32            ;Keyboard buffer
  162. TextLen    Db    0
  163. TextBuf    Db    32 Dup (0)        ;Scan text
  164.  
  165. Prompt    Db    'Command:'
  166. Spaces    Db    32 Dup (32)        ;Scan text entered
  167.     Db    'Keys: PgUp PgDn Arrows ESC=exit ?=Help '
  168. Pr_Len    Equ    This Byte - Prompt
  169.  
  170. TextMsg    Db    '*** Text not found ***'
  171. EofMsg    Db    '   *** End-of-file ***'
  172. EofLen    Equ    This Byte - EofMsg
  173.  
  174. Work    Db    'LIST'            ;current logical record
  175. Keyin    Db    64            ;keyboard buffer size
  176. Keyout    Db    0            ; and length read
  177. Filenm    Db    76 Dup (0)        ;d:path\filename.ext
  178.  
  179. Askfile    Db    13,10,'Enter filename: $'
  180. Openmsg    Db    '  Open failed, return code='
  181. Opencod    Dw    '00'
  182.     Db    '$'
  183. Code2    Db    'File not found $'
  184. Code3    Db    'Path not found $'
  185. Code4    Db    'Too many files $'
  186. Code5    Db    'Access denied  $'
  187. Sorry    Db    Cr,Lf,'Sorry, DOS 2.0 or later required',Cr,Lf,'$'
  188.  
  189.     Org    Work+256
  190. Workx    Equ    $-Work
  191. Stack    Db    64 Dup (0)        ;may overlay above constants
  192. Stackx    Equ    $
  193.  
  194.     Page
  195. ;
  196. ;    Command letters and keys
  197.  
  198. What1    Db    13,32,27,81    ;Cr,Sp,Esc,Q
  199.     Db    68,85,63,72    ;D,U,?,H
  200.     Db    47,82,76,84    ;/,R,L,T
  201.     Db    80,65,78,88    ;P,A,N,X
  202.     Db    66        ;B
  203. Num1    Equ    $-What1            ;How many letters
  204.  
  205. What2    Db    77,75,73,81    ;->,<-,PgUp,PgDn
  206.     Db    71,72,61,80    ;HOME,^,F3,v
  207.     Db    59,68,79,119    ;F1,F10,END,^HOME
  208.     Db    115,132,118    ;^<-,^PgUp,^PgDn
  209. Num2    Db    $-What2            ;Number    of control keys
  210.  
  211. Where1    Dw    Offset NxtPage,Offset NxtPage,Offset Close, Offset Close
  212.     Dw    Offset NxtPage,Offset Back,   Offset Got_H, Offset Got_H
  213.     Dw    Offset Got_S,  Offset Right,  Offset Left,  Offset Top
  214.     Dw    Offset Up1,    Offset Got_Rs, Offset Down1, Offset Close
  215.     Dw    Offset Bottom
  216.  
  217. Where2    Dw    Offset Right,  Offset Left,   Offset Back,  Offset NxtPage
  218.     Dw    Offset Top,    Offset Up1,    Offset Got_Rs,Offset Down1
  219.     Dw    Offset Got_H,  Offset Close,  Offset Bottom,Offset Home
  220.     Dw    Offset Scroll0,Offset Top,    Offset Bottom
  221.     Page
  222. HelpMsg    Db    CR,LF,LF
  223.     Db    9,'LIST 1.5 by Vernon Buerg',CR,LF,LF
  224.     Db    9,'Commands and keys:',CR,LF
  225.     Db    CR,LF,9,'Enter        ',9,9,'continue to next page'
  226.     Db    CR,LF,9,'ESCape or F10',9,9,'terminate'
  227.     Db    CR,LF,9,'HOME or T    ',9,9,'restart from Top of file'
  228.     Db    CR,LF,9,'END or B     ',9,9,'skip to Bottom of block'
  229.     Db    CR,LF,9,'PgDn or D    ',9,9,'scroll Down one page'
  230.     Db    CR,LF,9,'PgUp or U    ',9,9,'scroll Up one page'
  231.     Db    CR,LF,9,'H or ?       ',9,9,'list Help for keys'
  232.     Db    CR,LF
  233.     Db    CR,LF,9,'left-arrow   ',9,9,'scroll Left 20 columns'
  234.     Db    CR,LF,9,'right-arrow  ',9,9,'scroll Right 20 columns'
  235.     Db    CR,LF,9,'up-arrow     ',9,9,'Previous, up one line'
  236.     Db    CR,LF,9,'down-arrow   ',9,9,'Next, down one line'
  237.     Db    CR,LF
  238.     Db    CR,LF,9,'/text        ',9,9,'find text'
  239.     Db    CR,LF,9,'A or F3      ',9,9,'find text Again'
  240.     Db    '$'
  241.  
  242.     Page
  243. ;
  244. ;    Initialization
  245.  
  246. Start:    Mov    BX,PgmSize        ;Length    of Cseg    and Stack
  247.     Mov    AH,4Ah            ;Modify    allocated memory
  248.     Int    21h            ; using    ES from    entry
  249.  
  250.     Call    GetParm            ;Get filename from command line
  251. Openit:    Call    Open
  252.     Jz    Init
  253.     Ret
  254.  
  255. Close:    Mov    BX,Handle        ;End of    job
  256.     Mov    AH,3Eh            ;Close a file handle
  257.     Int    21h
  258.  
  259.     Mov    AX,0600h        ;Clear the screen
  260.     Sub    BL,BL
  261.     Mov    BH,Foregrd
  262.     Sub    CX,CX            ;Screen    begin
  263.     Mov    DX,184Fh        ; and end
  264.     Int    10h
  265.     Ret                ;Return    to DOS
  266.  
  267.     Page
  268. ;
  269. ; Allocate memory for file buffer
  270.  
  271. Init:    Mov    BX,1000h        ;Try for 64K more
  272. GetMem:    Mov    AH,48h            ;Allocate memory
  273.     Int    21h
  274.     Jc    GetMem            ;Get what there    is
  275.  
  276.     Mov    RecAddr,AX        ;Save segment addr
  277.     Mov    AX,BX            ;Paragraphs available
  278.     Sub    AX,32            ; less one sector
  279.     Mul    Psize            ; as bytes available
  280.     Mov    Blksize,AX        ; and as file read size
  281.  
  282.     Call    InitCrt            ;Get CRT buffer    constants
  283.  
  284.     Call    Set1            ;Display title line
  285.  
  286.     Call    Set25            ;Display prompt    line
  287.  
  288.     Page
  289. ;
  290. ; Extract next logical record for display
  291.  
  292. Read1:    Call    ReadBlk            ;Load next block
  293.     Mov    BL,Normal
  294.     Mov    Attr,BL
  295.     Jnz    Read2
  296.     Jmp    AtEnd
  297.  
  298. Read2:    Dec    Row            ;Spot for incomplete record
  299.     Cmp    Numlf,0            ;record    ended in LF?
  300.     Je    GetNext            ;no, have col/row
  301.     Inc    Row            ;yes, row stays    where it is
  302.     Mov    Col,1            ; and in column    1
  303.  
  304. GetNext:
  305.     Mov    AX,Index        ;Is record in buffer?
  306.     Cmp    AX,Last
  307.     Jb    GotNext
  308.     Jmp    AtEnd
  309. GotNext:
  310.     Call    ListOne            ;Display next logical record
  311.     Mov    CX,Reclen
  312.     Add    Col,CL            ;For end-of-block
  313.     Mov    DH,Row
  314.     Cmp    DH,25            ;Exceeded screen?
  315.     Jne    TestEor            ; no, read next    record
  316.     Cmp    NumLF,0            ;Ended in LF?
  317.     Jne    Wait
  318.  
  319. TEstEor:Jmp Read2            ;End-of-records?
  320.  
  321. Wait:    Mov    AH,0            ;Wait and read console
  322.     Int    16h
  323.  
  324.     Mov    SI,Offset Spaces    ;Clear prompt line
  325.     Call    Msg25
  326.     Page
  327. ;
  328. ; Process keyboard (command) input
  329.  
  330.     Cmp    AL,27            ;ESCape    to exit?
  331.     Jne    Chk00
  332.     Jmp    Close
  333.  
  334. Chk00:    Cmp    AL,0            ;Control char?
  335.     Jne    Chk_97            ; no, a    letter
  336.     Xchg    AL,AH            ; yes, get extended code
  337.     Mov    DI,Offset What2
  338.     Mov    BP,Offset Where2
  339.     Mov    CL,Num2
  340.     Jmp    Short Control
  341.  
  342. Chk_97:    Cmp    AL,97            ;Lower case?
  343.     Jl    Upper
  344.     Sub    AL,32            ;Yes, make upper
  345.  
  346. Upper:    Mov    DI,Offset What1        ;Letter    table
  347.     Mov    BP,Offset Where1    ;Where-to-go list
  348.     Mov    CL,Num1            ;Number    of entries
  349.  
  350. Control:Mov    SI,DI            ;Find letter/code
  351.     Mov    CH,0            ;Number    in list
  352.     Push    DS
  353.     Pop    ES
  354.     Repnz    Scasb
  355.     Jne    Wait            ; if not found
  356.     Dec    DI            ;Point to letter/code
  357.     Sub    DI,SI            ;Offset    into list
  358.     Shl    DI,1            ; times    word size
  359.     Mov    BX,Word    Ptr DS:[DI][BP]
  360.     Jmp    BX            ;Go to routine
  361.  
  362. Right:    Cmp    Scroll,220        ;right arrow
  363.     Jb    Got77
  364.     Jmp    Wait
  365. Got77:    Add    Scroll,20
  366.     Jmp    BackUp
  367.  
  368. Scroll0:Mov    Scroll,0        ;ctrl-left-arrow
  369.     Jmp    BackUp
  370.  
  371. Left:    Cmp    Scroll,0        ;left arrow
  372.     Jne    Got75
  373.     Jmp    Wait
  374. Got75:    Sub    Scroll,20
  375.     Jmp    BackUp
  376.  
  377. Got_Rs:    Call    ReScan            ;F3 for    re-scan
  378.     Jmp    NxtPage
  379.  
  380. Got_H:    Call    Help            ;List key functions
  381.     Call    Back1
  382.     Jmp    Wait
  383.  
  384. Got_S:    Call    Scan            ;Find text
  385.     Jmp    NxtPage
  386.  
  387.     Page
  388. NxtPage:                ;Advance to next "page"
  389.     Mov    AX,Index
  390.     Cmp    AX,Last            ;At end    of file?
  391.     Jae    BWait
  392.     Mov    Current,AX
  393.     Mov    DH,2            ;Restart at row    2
  394.     Mov    Row,DH
  395.     Call    Clear            ;Clear screen
  396.     Jmp    TestEor
  397.     Page
  398. ; Scroll up one    line
  399.  
  400. Up1:    Cmp    First,0            ;Already at top?
  401.     Jne    Up12            ; no, scroll up    one more
  402. Bwait:    Jmp    AtEnd            ; yes, ignore it
  403.  
  404. Up12:    Call    Scroll_Up        ;Display down one line
  405.     Mov    AX,Index        ; to empty top line
  406.     Mov    Current,AX        ;Save bottom line ptr
  407.     Mov    AX,First
  408.     Mov    Index,AX
  409.     Call    UpOne
  410.     Mov    Row,2
  411.     Mov    Col,1
  412.     Call    ListOne
  413.     Mov    AX,Current
  414.     Mov    Index,AX
  415.     Call    UpOne
  416.     Jmp    Wait
  417.  
  418. Home:    Mov    Index,0            ;Restart from top of block
  419.     Jmp    NxtPage
  420.  
  421.  
  422. AtEnd:    Mov    SI,Offset EofMsg    ;say End-of-file
  423.     Call    Msg25
  424.     Jmp    Wait
  425.  
  426. Bottom:    Mov    AX,Last            ;Position to last record
  427.     Mov    Index,AX
  428.     Jmp    BackUp
  429.  
  430. Top:    Sub    CX,CX            ;Restart
  431.     Mov    AL,0            ; from beginning
  432.     Sub    DX,DX
  433.     Mov    AH,42h            ;Reposition file
  434.     Mov    BX,Handle
  435.     Int    21h
  436.     Call    Clear
  437.     Mov    Row,2
  438.     Mov    Col,1
  439.     Mov    First,0
  440.     Mov    Blknum,0
  441.     Jmp    Read1
  442.  
  443. ; Scroll Up one    page
  444.  
  445. Back:    Call    Back1            ;Back up to top    of page
  446. BackUp:    Call    Back1            ; or to    previous page
  447.     Jmp    Nxtpage
  448.  
  449. ; Scroll down one line
  450.  
  451. Down1:    Mov    AX,Index        ;Current line
  452.     Cmp    AX,Last            ;At end    of file?
  453.     Jb    Down2
  454.     Jmp    AtEnd
  455.  
  456. Down2:    Mov    Current,AX
  457.     Mov    AX,First
  458.     Mov    Index,AX
  459.     Call    GetRec            ;Set new first ptr
  460.     Mov    AX,Index
  461.  
  462. Down3:    Call    Scroll_Dn        ;Move display up one line
  463.     Mov    AX,Index
  464.     Mov    First,AX
  465.     Mov    AX,Current
  466.     Mov    Index,AX
  467.     Mov    Row,24
  468.     Mov    Col,1
  469.     Jmp    GetNext
  470.  
  471. ; Scroll Up one    page
  472.  
  473. Back1    Proc    Near
  474.     Mov    CX,23            ;Back to current page
  475. Back0:    Call    UpOne
  476.     Loop    Back0
  477.     Mov    Col,1
  478.     Ret
  479. Back1    Endp
  480.  
  481. ; Scroll up one    line
  482.  
  483. UpOne    Proc    Near            ;Position to previous line
  484.     Push    CX
  485.     Mov    CX,2
  486.     Cmp    Index,0            ;Already at top?
  487.     Je    Up1d            ; yes, no change
  488. Up1a:    Mov    ES,Recaddr        ;Buffer    start
  489. Up1b:    Mov    DI,Index        ;Offset    into buffer
  490.     Cmp    ES:Byte    Ptr[DI],LF    ;A line    feed?
  491.     Je    Up1c
  492.     Dec    Index
  493.     Jnz    Up1b            ;Out of    buffer?
  494. Up1e:    Mov    Index,0            ; yes, stop at top
  495.     Jmp    Up1d
  496.  
  497. Up1c:    Dec    Index            ;Passed    CR
  498.     Jz    Up1d
  499.     Loop    Up1b
  500.     Inc    Index            ;Skip over LF
  501. Up1d:    Pop    CX
  502.     Ret
  503. UpOne    Endp
  504.     Page
  505. ;
  506. ;    Place Records into Screen Buffer
  507.  
  508.     Assume    CS:Cseg,DS:Cseg,ES:Nothing
  509. Display    Proc    Near
  510.     Push    AX
  511.     Push    BX
  512.     Push    CX            ;Line length
  513.     Push    DX            ;Row,col
  514.     Push    DI
  515.     Push    ES
  516.     Push    SI            ;Addr of record
  517.  
  518.     Sub    AX,AX
  519.     Mov    AL,DH            ;get row
  520.     Sub    DH,DH
  521.     Mov    DI,DX            ; and column
  522.     Dec    DI            ;adjust    for zero offset
  523.     Dec    AX
  524.     Cmp    CX,0            ;Skip null strings
  525.     Jng    Dsp9
  526.     Cmp    CX,80            ;Can only display 80
  527.     Jbe    Dsp1            ; cols at a time
  528.     Mov    CX,80
  529.  
  530. Dsp1:    Mul    Crt_Col            ;AX = row * chars per line
  531.     Add    DI,AX            ;DI = chars from start of screen
  532.     Shl    DI,1            ;adjust    for attribute bytes
  533.  
  534.     Mov    DX,Crt_Prt        ;Addr of card status port
  535.     Mov    ES,Crt_Buf        ;Addr of display buffer
  536.  
  537.     Mov    BH,Attr            ;Display attribute
  538. Dsp2:    Lodsb                ;Next character
  539.     Cmp    AL,' '            ;Don't bother with blanks
  540.     Jae    Dsp3            ; or control chars
  541.     Add    DI,2
  542.     Jmp    Dsp4
  543.  
  544. Dsp3:    Mov    BL,AL            ;Char and attr
  545.     Call    Displa
  546. Dsp4:    Loop    Dsp2
  547.  
  548. Dsp9:    Pop    SI
  549.     Pop    ES
  550.     Pop    DI
  551.     Pop    DX
  552.     Pop    CX
  553.     Pop    BX
  554.     Pop    AX
  555.     Ret
  556.  
  557. ;  Wait    for horzontal retrace
  558.  
  559. Displa:    In    AL,DX            ;Port status
  560.     Test    AL,1            ;Is it low?
  561.     Jnz    Displa            ; no, keep checking
  562.     Cli                ; yes, turn off    interrupts
  563. Disphi:    In    AL,DX            ;Get status
  564.     Test    AL,1            ;Is it high?
  565.     Jz    Disphi            ; no, keep checking
  566.  
  567.     Mov    AX,BX            ;Attrib    and char
  568.     Stosw                ; to display buffer
  569.     Sti
  570.     Ret
  571.  
  572. Display    Endp
  573.     Page
  574. ;
  575. ; Display next logical record
  576.  
  577. ListOne    Proc    Near
  578.     Cmp    Row,2
  579.     Jne    List1
  580.     Mov    AX,Index
  581.     Mov    First,AX        ;Ptr to    current    top line
  582. List1:    Call    GetRec            ;Return    logical    record
  583.     Mov    CX,Reclen        ;Record    size
  584.     Sub    CL,Numlf        ; less LF
  585.     Sub    CL,Numcr        ; less CR
  586.     Mov    Reclen,CX
  587.     Or    CX,CX            ;blank line?
  588.     Jz    List9            ;yes, increment    row only
  589.  
  590.     Mov    SI,Offset Work        ;Addr of record
  591.     Cmp    Row,2            ;Is row    valid?
  592.     Jae    List2
  593.     Mov    Row,2
  594. List2:    Mov    DH,Row            ;destination row
  595.     Mov    DL,Col            ; and column
  596.     Add    SI,Scroll
  597.     Sub    CX,Scroll
  598.     Call    Display            ;put into screen buffer
  599.  
  600. List9:    Inc    Row            ;Bump to next row
  601.     Mov    BL,Normal        ; restore attribute
  602.     Mov    Attr,BL
  603.     Ret
  604. ListOne    Endp
  605.     Page
  606. ;
  607. ;    GetRec - Extract next logical record
  608. ;
  609. ; Scan the buffer for special characters and copy wanted
  610. ; data to field    WORK. A    logical    record ends in an LF and/or CR.
  611. ; Tabs are expanded and    x'0F' is deleted.
  612.  
  613. GetRec    Proc    Near
  614.     Push    ES
  615.     Push    CX
  616.     Push    SI
  617.     Push    DI
  618.  
  619. GetR:    Test    Switch1,Eor        ;Found end of file?
  620.     Jz    GetR0
  621.     Mov    AX,Last            ; yes, set ptr to EOF
  622.     Mov    Index,AX
  623.     Call    ReadBlk            ;Try for next block
  624.     Jnz    GetR0
  625.     Jmp    GetRd
  626.  
  627. GetR0:    Sub    DI,DI            ;Record    size/output offset
  628.     Mov    Word Ptr NumLF,DI    ;zero NUMLF and    NUMCR
  629.     And    Switch2,0FFh-Nodata
  630.     Mov    ES,RecAddr        ;Set buffer segment addr
  631.  
  632. GetR2:    Mov    SI,Index        ;Current input offset
  633.     Mov    AL,ES:[SI]        ;Copy a    char
  634.     Cmp    AL,Eof            ;End of    file?
  635.     Jne    GetR3
  636.     Mov    Reclen,DI
  637.     Or    Switch1,Eor        ;Indicate end-of-file
  638.     Jmp    GetR
  639.  
  640. GetR3:    Cmp    AL,09h            ;Is it TAB?
  641.     Jne    GetR4
  642.     Mov    CX,DI            ;Current work size
  643.     Add    CX,8            ;Round to 8-bytes
  644.     And    CX,0FFF8h
  645.     Sub    CX,DI            ;Number    of blanks
  646. GetR3b:    Mov    Work[DI],' '        ; to insert
  647.     Inc    DI
  648.     Loop    GetR3b
  649.     Inc    Index            ;Bump input offset
  650.     Jmp    GetR2            ; and get next char
  651.  
  652. GetR4:    And    AL,7Fh            ;Assure    readable
  653.     Mov    Work[DI],AL        ;Copy character
  654.     Inc    DI            ;Incr output offset
  655.     Inc    Index            ; and input offset
  656.     Cmp    AL,Cr            ;Is it a CR?
  657.     Jne    GetR5
  658.     Inc    NumCR            ;Yes, incr count
  659.  
  660. GetR5:    Cmp    AL,' '
  661.     Je    GetR7
  662.     Cmp    AL,Lf            ;Is it line feed?
  663.     Jne    GetR6
  664.     Inc    NumLF            ;Yes, incr count
  665.     Jmp    GetR8
  666.  
  667. GetR6:    Or    Switch2,Nodata        ;Non-space found
  668.  
  669. GetR7:    Cmp    DI,255            ;Record    too big?
  670.     Je    GetR8            ;Chop record at    255 bytes
  671.     Jmp    GetR2
  672.  
  673. GetR8:    Mov    Reclen,DI
  674.     Cmp    Work,0Fh        ;If record begins with "sun"
  675.     Jne    GetR9            ; symbol, skip it
  676.     Jmp    GetR0
  677.  
  678. GetR9:    Test    Switch2,Nodata        ;If all    blank
  679.     Jnz    GetRd
  680.     Jmp    GetR0            ; read another one
  681.  
  682. GetRd:    Pop    DI
  683.     Pop    SI
  684.     Pop    CX
  685.     Pop    ES
  686.     Ret
  687. GetRec Endp
  688.  
  689.     Page
  690. ;
  691. ; Read a block
  692.  
  693. ReadBlk    Proc    Near
  694.     Mov    Switch1,0        ;reset EOR flag
  695.     Mov    BX,Handle        ;get file handle from open
  696.     Mov    CX,Blksize        ;bytes to read
  697.     Push    DS
  698.     Mov    DS,RecAddr        ;addr of gotten    memory
  699.     Sub    DX,DX            ; with zero offset
  700.     Mov    AH,3Fh
  701.     Int    21H            ;read a    block
  702.     Pop    DS
  703.  
  704.     Or    AX,AX            ;Any bytes read?
  705.     Jz    ReadB2            ; no, return with ZF
  706.     Mov    Last,AX            ; yes, set record pointers
  707.     Mov    Index,0
  708.     Mov    First,0
  709.     Mov    Current,0
  710.     Inc    Blknum
  711.     Mov    DI,Last            ;Append    EOF to buffer
  712.     Mov    ES,RecAddr
  713.     Mov    Byte Ptr ES:[DI],1Ah
  714. ReadB2:    Ret
  715. Readblk    Endp
  716.  
  717.     Page
  718. ;
  719. ; Scan for text    entered    after slash (/)
  720.  
  721. ReScan    Proc
  722.     Push    DI
  723.     Push    SI
  724.     Push    DS
  725.     Pop    ES
  726.     Jmp    Scan1
  727.  
  728. Scan:    Push    DI
  729.     Push    SI
  730.     Push    DS
  731.     Pop    ES
  732.     Mov    TextMax,32        ;Max string length
  733.     Mov    DX,Offset TextMax
  734.     Mov    AH,0Ah            ;Read console
  735.     Int    21h
  736.  
  737. Scan1:    Sub    CX,CX
  738.     Or    CL,TextLen        ;Get and test length
  739.     Jz    NoMatch            ; none,    return as is
  740.     Mov    AX,First        ;Start with current screen
  741.     Mov    Index,AX
  742.     Call    GetRec            ;Skip top line
  743.  
  744. Scan3:    Call    GetRec            ;Read next logical record
  745.     Test    Switch1,Eor        ;End of    data?
  746.     Jnz    NoMatch            ; yes, NOT FOUND
  747.     Mov    AX,Index        ;Current record    ptr
  748.     Cmp    AX,Last            ;Beyond    buffer?
  749.     Jae    NoMatch            ; yes, NOT FOUND
  750.     Mov    CX,RecLen
  751.     Sub    CL,TextLen        ;Columns to search
  752.     Jle    Scan3
  753.  
  754.     Mov    AL,TextBuf        ;Scan for first    char in    record
  755.     Mov    DI,Offset Work        ;Current record    data
  756.     Repnz    Scasb
  757.     Jne    Scan3            ; not found
  758.     Cmp    TextLen,1        ;Whole thing done?
  759.     Je    Match
  760.     Sub    CH,CH
  761.     Mov    CL,TextLen        ;Search    for rest of it
  762.     Dec    CL
  763.     Mov    SI,Offset TextBuf+1
  764.     Repe    Cmpsb
  765.     Jne    Scan3
  766.     Or    CX,CX            ;Found it?
  767.     Jnz    Scan3            ; no, try next record
  768.  
  769. Match:    Call    Set25            ;Restore prompt    line
  770.     Mov    Attr,Blink        ; and blink
  771.     Call    UpOne
  772.     Jmp    Scaned
  773.  
  774. NoMatch:Mov    AX,First        ;Not found,
  775.     Mov    Index,AX        ; restart at last page
  776.     Call    Set25            ;Restore prompt    line
  777.  
  778.     Mov    SI,Offset TextMsg    ;Say TEXT NOT FOUND
  779.     Add    Special,128        ;Make it blink
  780.     Call    Msg25
  781.     Sub    Special,128
  782.     Mov    Switch1,0
  783.     Mov    Col,1
  784.  
  785. Scaned:    Pop    SI
  786.     Pop    DI
  787.     Ret
  788. ReScan    Endp
  789.     Page
  790. ;
  791. ; Clear    screen or records window
  792.  
  793. Clear    Proc    Near            ;Clear entire screen
  794.     Push    AX
  795.     Push    BX
  796.     Push    CX
  797.     Push    DX
  798.  
  799.     Mov    AX,0600h
  800.     Mov    BH,Foregrd
  801.     Jmp    Scroller
  802.  
  803. Scroll_Dn:                ;Scroll    list window down
  804.     Push    AX
  805.     Push    BX
  806.     Push    CX
  807.     Push    DX
  808.  
  809.     Mov    AX,0601h
  810.     Mov    BH,Foregrd
  811.     Jmp    Scroller
  812.  
  813. Scroll_Up:                ;Scroll    list window up
  814.     Push    AX
  815.     Push    BX
  816.     Push    CX
  817.     Push    DX
  818.  
  819.     Mov    AX,0701h
  820.     Mov    BH,Foregrd
  821. Scroller:
  822.     Mov    CX,0100h        ;Screen    begin
  823.     Mov    DX,174Fh        ; and end
  824.     Int    10h
  825.  
  826.     Pop    DX
  827.     Pop    CX
  828.     Pop    BX
  829.     Pop    AX
  830.     Ret
  831. Clear    Endp
  832.     Page
  833. ;
  834. ;    Set top title line
  835.  
  836. Set1    Proc    Near
  837.     Mov    AX,0600h        ;Clear the screen
  838.     Sub    BL,BL
  839.     Mov    BH,Foregrd
  840.     Sub    CX,CX            ;Screen    begin
  841.     Mov    DX,184Fh        ; and end
  842.     Int    10h
  843.  
  844.     Mov    Word Ptr Work+4,0000h    ;Title in work area
  845.     Mov    DH,1            ;Row 1
  846.     Mov    DL,DH            ;Column    1
  847.     Mov    SI,Offset Work
  848.     Mov    CX,79            ;Length
  849.     Mov    BL,Special        ;Hi-intensity or yellow
  850.     Mov    Attr,BL
  851.     Call    Display
  852.     Ret
  853. Set1    Endp
  854.  
  855. ;    Set prompt line
  856.  
  857. Set25    Proc    Near
  858.     Push    DI
  859.     Push    SI
  860.     Mov    DH,25            ;set row
  861.     Mov    DL,1            ; and column
  862.     Mov    CX,Pr_Len        ; length
  863.     Mov    BL,Special
  864.     Mov    Attr,BL
  865.     Mov    SI,Offset Prompt
  866.     Call    Display
  867.  
  868.     Mov    AH,2            ;Set cursor position
  869.     Mov    DX,1808h        ; to row 25, col 9
  870.     Mov    BX,0            ; page zero
  871.     Int    10H
  872.     Pop    SI
  873.     Pop    DI
  874.     Ret
  875. Set25    Endp
  876.  
  877. ;    Display message on prompt line
  878.  
  879. Msg25    Proc    Near
  880. ;    Push    SI            ;Ptr to    msg text
  881.     Mov    DH,25            ;Clear message area
  882.     Mov    DL,10            ; its column
  883.     Mov    CX,EofLen        ; length
  884.     Mov    BL,Special        ;Hi-intensity or yellow
  885.     Mov    Attr,BL
  886.     Call    Display
  887.     Mov    BL,Normal
  888.     Mov    Attr,BL
  889.     Ret
  890. Msg25    Endp
  891.  
  892. ;
  893. ; Initialize display constants
  894.  
  895. InitCrt    Proc    Near
  896.     Push    ES
  897.     Mov    AX,Bios            ;Point to BIOS data
  898.     Mov    ES,AX
  899.     Mov    CX,ES:Cols        ;Save display columns
  900.     Mov    Crt_Col,CX
  901.     Mov    DX,ES:A6845        ;Save card base    addr
  902.     Add    DX,6            ; point    to status port
  903.     Mov    Crt_Prt,DX
  904.     Mov    Crt_Buf,0B800h        ;Default to color card
  905.     Mov    BX,ES:Flag
  906.     And    BX,30h
  907.     Cmp    BX,30h            ;Is it mono card?
  908.     Jne    CrtSet            ; no, set for color
  909.     Mov    Crt_Buf,0B000h        ; yes, point to    mono buffer
  910. CrtSet:    Pop    ES
  911.     Ret
  912. InitCrt    Endp
  913.     Page
  914. ;
  915. ; HELP - Display command key usage
  916.  
  917. Help    Proc    Near            ;Describe the commands
  918.     Call    Clear
  919.     Mov    DX,0200h        ;Position cursor
  920.     Mov    AH,2
  921.     Sub    BH,BH
  922.     Mov    BL,Foregrd
  923.     Int    10h
  924.     Mov    DX,Offset HelpMsg    ;List the text lines
  925.     Mov    AH,9
  926.     Int    21h
  927.     Mov    AH,2            ;restore position
  928.     Mov    DX,1808h        ; to row 25, col 9
  929.     Sub    BX,BX
  930.     Int    10H
  931.     Ret
  932. Help    Endp
  933.     Page
  934. ;
  935. ; Get file name    from command line
  936.  
  937. GetParm    Proc    Near
  938.     Xor    AX,AX            ;For COM, CS=DS=ES
  939.     Xor    CX,CX
  940.     Mov    AL,Byte    Ptr DS:[80h]    ;Gather    file name from command line
  941.     Or    CX,AX            ;Any supplied?
  942.     Jz    GetFile            ; no, ask for it
  943.     Mov    DI,Offset Filenm    ; yes, point to target
  944.     Mov    SI,81h            ;Offset    to parm    in PSP
  945. Blanks:    Lodsb
  946.     Cmp    AL,' '            ;Skip any blanks
  947.     Je    Skipit
  948.     Stosb                ;Copy parm to FileNm
  949. Skipit:    Loop    Blanks
  950.     Ret
  951.  
  952. GetFile:
  953.     Mov    DX,Offset AskFile    ;Prompt    for file name
  954.     Mov    AH,9
  955.     Int    21H
  956.     Mov    AH,0AH            ;Buffered kybd input DOS req
  957.     Mov    DX,Offset Keyin
  958.     Int    21h
  959.  
  960.     Sub    BL,BL
  961.     Or    BL,Keyout        ;Number    of chars read
  962.     Jz    GetFile            ; none,    ask for    name
  963.     Mov    Filenm[BX],0        ;Overlay CR to make ASCIIZ name
  964.     Ret
  965. GetParm    Endp
  966.  
  967. ;  Open    the file to list
  968.  
  969. Open    Proc    Near
  970.     Mov    OpenCod,0        ;Reset open return code
  971.     Mov    DX,Offset Filenm    ;OPEN file
  972.     Mov    AL,0            ; for read only
  973.     Mov    AH,3DH
  974.     Int    21H
  975.     Mov    Handle,AX        ;save file handle
  976.     Jnc    Opened            ;if OPEN okay
  977.  
  978.     Mov    OpenCod,AX
  979.     Cmp    AL,2            ;Check code to be
  980.     Jl    Error            ; within our messages
  981.     Cmp    AL,5
  982.     Ja    Error
  983.     Sub    BX,BX            ;For message index
  984.     Mov    BL,AL
  985.     Mov    CL,4
  986.     Shl    BX,CL
  987.     Lea    DX,Code2-32[BX]        ;Point to msg text
  988.     Jmp    Error2
  989.  
  990. Error:    Aam                ;Other return codes
  991.     Xchg    AL,AH
  992.     Or    OpenCod,AX
  993.     Mov    DX,Offset OpenMsg
  994.  
  995. Error2:    Mov    AH,9
  996.     Int    21H            ;say OPEN FAILED
  997. Opened:    Cmp    OpenCod,0
  998.     Ret
  999. Open    Endp
  1000.  
  1001. List    Endp
  1002.  
  1003. PgmSize    Equ    ($-Cseg+16)/16        ;Program size in paragraphs
  1004.  
  1005. Cseg    Ends
  1006.  
  1007.     End    List